#!/usr/bin/perl
use threads;
use threads::shared;

#change the smloops for testing other interfaces
$smloops = '../../interfaces/oops/smloops';
$tests_dir= '../testcases/';

opendir(DIR,$tests_dir);
@tests = grep{/^[a-zA-Z_-]*.mod$/ && -f "$tests_dir/$_"} readdir(DIR);
closedir(DIR);

@testnames = ();
foreach $file (@tests) {
	$file = substr($file,0,length($file)-4);
	push(@testnames,$file);
}

$num_pass = 0;
$num_fail = 0;
$num_tol = 0;
foreach $test (@testnames) {
	print "\nTestCase:[$test]\n";
	`$smloops $tests_dir$test.mod $tests_dir$test.dat > output.tmp 2>&1`;
	
	#The actual result is either UNBOUNDED or Solution Found.
	#can add for additonal result cases if necessary.
	chop($result = `grep UNBOUNDED output.tmp`);
	if($result eq ""){
		chop($result =`grep Sol output.tmp`);
	}

	#calculate expect result
	chop($expect = `cat ../testcases/$test.out`);
	print "Actual:  [$result]\n";
	print "Expected:[$expect]\n";

	#Testing equal	
	if($result eq $expect) {
		print "TestCase: [$test] PASS! \n";
		$num_pass++;
	}
	else {
		print "TestCase: [$test] FAIL!! \n";
		$num_fail++;
		`mv output.tmp fail$num_fail.tmp`;
	}
	print "\n";
	$num_tol ++;
}
`rm output.tmp`;
print "Summary: Total Tests[$num_tol] - PASSED[$num_pass] - FAILED[$num_fail]\n";

